#pragma once

#include <algorithm>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>

namespace solution_049
{

class Solution
{
public:
    std::vector< std::vector<std::string> > groupAnagrams(std::vector<std::string>& strs) {
        std::unordered_map< std::string, std::vector<std::string> > buckets;
        for (size_t i = 0; i < strs.size(); ++i) {
            auto str = strs.at(i);
            std::sort(str.begin(), str.end());
            buckets[str].push_back(std::move(strs.at(i)));
        }
        std::vector< std::vector<std::string> > groups;
        for (auto& [key, value] : buckets)
            groups.push_back(std::move(std::move(value)));
        return groups;
    }
};

}  /* namespace solution_049 */
